<template>
  <div class="warp model" v-show="modelValue">
    <div class="warp-pop" v-if="type === 'default'" :style="{ width: width + 'px' }">
      <div class="warp-header">
        <span>{{ title }}</span>
        <el-icon class="close" @click="onClose"><Close /></el-icon>
      </div>
      <div class="warp-body">
        <slot></slot>
      </div>
      <div class="warp-footer">
        <el-button @click="onClose()">取消</el-button>
        <el-button type="primary" @click="onOk()">确定</el-button>
      </div>
    </div>
    <!-- 删除提示框 -->
    <div class="warp-pop" v-if="type === 'delete'" :style="{ width: width + 'px' }">
      <div class="warp-header">
        <span></span>
        <el-icon class="close" @click="onClose"><Close /></el-icon>
      </div>
      <div class="warp-body-delete">
        <p class="d-flex a-center j-center">
          <Svg size="30" name="提示"></Svg><span class="ml10">{{ title }}</span>
        </p>
      </div>
      <div class="warp-footer">
        <el-button @click="onClose()">取消</el-button>
        <el-button type="primary" @click="onOk()">确定</el-button>
      </div>
    </div>
  </div>
</template>
<script setup>
import { Close, WarningFilled } from '@element-plus/icons-vue'
import Svg from '@/components/Svg.vue'
// 接受父组件数据
defineProps({
  title: { type: String, default: '' },
  modelValue: { type: Boolean, default: false },
  type: { type: String, default: 'default' },
  width: { type: Number, default: 400 }
})
// 子组件通过事件向父组件传值
const toParent = defineEmits(['onClose', 'onOk'])
//取消
const onClose = () => {
  toParent('onClose', false)
}
//确定
const onOk = () => {
  toParent('onOk', false)
}
console.log('弹窗')
</script>
<style lang="scss" scoped>
.warp {
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  background-color: rgba(0, 0, 0, 0.5);
  .warp-pop {
    font-size: 14px;
    margin: 100px auto;
    position: relative;
    background: #ffffff;
    z-index: 0;
    -webkit-animation: zoom 0.6s;
    animation: zoom 0.6s;
    overflow: auto;
    .warp-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 15px 20px;
      .close {
        cursor: pointer;
        &:hover {
          color: #5cadff;
        }
      }
    }
    .warp-body {
      border-top: 1px solid #eeeeee;
      border-bottom: 1px solid #eeeeee;
    }
    .warp-footer {
      text-align: right;
      height: 48px;
      line-height: 48px;
      padding: 0 20px;
      margin-bottom: 10px;
    }
    .warp-body-delete {
      margin: 20px 0;
    }
  }
  @keyframes zoom {
    from {
      transform: scale(0);
    }
    to {
      transform: scale(1);
    }
  }
}
</style>
